package office.action.hr;

import java.util.List;
import office.action.hr.form.QuitEntryForm;
import office.service.hr.IQuitEntryService;
import platform.common.action.BaseAction;

/**
 * 辞职申请
 * @author ibmsz
 *
 */
public class QuitEntryAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private IQuitEntryService quitEntryService;
	private QuitEntryForm objctForm;
	private String id;
	@SuppressWarnings("unchecked")
	private List wrapperList;
	
	public String quitEntryList()throws Exception{
		//TODO
		objctForm = new QuitEntryForm();
		objctForm.setUserId(getUserId());
		objctForm.setCheckRole(getUserRoleName());
		objctForm.setDeptId(getUserDepartmentId());
		objctForm.setCompanyId(getUserCompanyId());
		objctForm.setRoleDFlag(getRoleDFlag());
		//根据用户获取数据列表(查看内容为：自己提交的和需要审批的数据)
		wrapperList = quitEntryService.getQuitEntryList(objctForm);
		return "showList";
	}
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoAdd()throws Exception{
		
		return "gotoEdit";
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEdit()throws Exception{
		String userId = getUserId();
		objctForm = quitEntryService.getByUserId(userId);
		if(null==objctForm.getId() ||  objctForm.getId().equals("")){
			objctForm.setName(getUserCname());
			objctForm.setDept(getUserDepartmentName());
			objctForm.setOffice(getUserRoleName());
		}
		return "gotoEdit";
	}
	/**
	 * 添加或编辑数据
	 * @return
	 * @throws Exception
	 */
	public String editData() throws Exception{
		try {
			if(null==objctForm.getId() || objctForm.getId().equals("")){
				String userId = getUserId();
				objctForm.setUserId(userId);
				String roleId = getUserRoleName();
				objctForm.setEntryRole(roleId);
			}
			quitEntryService.editQuitEntry(objctForm);
			this.getAjaxMessagesJson().setMessage(true, "", "保存成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 初始化可用操作
	 * @return
	 * @throws Exception
	 */
	public String gotoEditXml()throws Exception{
		objctForm = quitEntryService.getById(id);
		return "editXml";
	}
	/**
	 * 初始化删除
	 * @return
	 * @throws Exception
	 */
	public String gotoDel()throws Exception{
		return "gotoDel";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delData()throws Exception{
		try {
			quitEntryService.deleteById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 确认提交审批页面
	 * @return
	 * @throws Exception
	 */
	public String gotoSubmitCheck()throws Exception{
		return "gotoSubmitCheck";
	}
	/**
	 * 提交审批
	 * @return
	 * @throws Exception
	 */
	public String submitCheck() throws Exception{
		try {
			quitEntryService.submitCheck(id);
			this.getAjaxMessagesJson().setMessage(true, "", "提交审批成功");
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	@SuppressWarnings("unchecked")
	public List getWrapperList() {
		return wrapperList;
	}

	@SuppressWarnings("unchecked")
	public void setWrapperList(List wrapperList) {
		this.wrapperList = wrapperList;
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public IQuitEntryService getQuitEntryService() {
		return quitEntryService;
	}
	public void setQuitEntryService(IQuitEntryService quitEntryService) {
		this.quitEntryService = quitEntryService;
	}
	public QuitEntryForm getObjctForm() {
		return objctForm;
	}
	public void setObjctForm(QuitEntryForm objctForm) {
		this.objctForm = objctForm;
	}
	
}
